<template>
  <div class="box">
    <div class="bg" />
    <div class="inp-box">
      <p>智慧园区-登录</p>
      <el-form ref="formRef" :model="formData" :rules="rules">
        <el-form-item class="item" label="账号" prop="username">
          <el-input v-model="formData.username" />
        </el-form-item>
        <el-form-item class="item" prop="password" label="密码">
          <el-input v-model="formData.password" show-password />
        </el-form-item>
        <el-form-item class="item">
          <el-checkbox>请勾选协议</el-checkbox>
        </el-form-item>
        <el-form-item>
          <el-button
            style="width: 500px; height: 45px"
            type="primary"
            @click="onSubmit"
          >登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { mapActions } from 'vuex'
export default {
  data() {
    return {
      formData: {
        username: 'demo',
        password: 'zh@hm#23'
      },
      rules: {
        username: [
          { required: true, message: '用户名不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ]
        // 复选框自定义校验
      }
    }
  },
  methods: {
    ...mapActions('user', ['LoginTokens']),
    async onSubmit() {
      // 点击表单校验
      await this.$refs.formRef.validate()
      // 点击后拿token
      await this.LoginTokens(this.formData)
    }
  }
}
</script>

<style lang="scss" scoped>
* {
  margin: 0;
  padding: 0;
}
.box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.inp-box {
  width: 500px;
  height: 500px;
  margin-right: 110px;
  p {
    font-size: 26px;
    padding-bottom: 65px;
  }
}
.bg {
  height: 100vh;
  width: 60vw;
  background-image: url("../../assets/common/login_back.svg");
  background-repeat: no-repeat;
  margin-right: 100px;
}

.item {
  margin-bottom: 20px;
}
</style>
